package com.example.hxds.bff.driver.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil;
import com.example.hxds.bff.driver.controller.form.*;
import com.example.hxds.bff.driver.service.OrderService;
import com.example.hxds.common.util.PageUtils;
import com.example.hxds.common.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author XUYANG
 * @Date 2024-03-20 19:36
 */
@RestController
@RequestMapping("/order")
@Tag(name = "OrderController",description = "订单服务web接口")
public class OrderController {
    @Resource
    private OrderService orderService;
    @PostMapping("/acceptNewOrder")
    @Operation(summary = "司机接单")
    @SaCheckLogin
    public R acceptNewOrder(@RequestBody @Valid AcceptNewOrderForm form){
        long driverId=StpUtil.getLoginIdAsLong();
        form.setDriverId(driverId);
        String res=orderService.acceptNewOrder(form);
        return R.ok().put("result",res);
    }
    @PostMapping("/searchDriverExecuteOrder")
    @Operation(summary = "查询司机正在进行的订单接口")
    @SaCheckLogin
    public R searchDriverExecuteOrder(@RequestBody @Valid SearchDriverExecuteOrderForm form){
        long driverId=StpUtil.getLoginIdAsLong();
        form.setDriverId(driverId);
        HashMap res=orderService.searchDriverExecuteOrder(form);
        return R.ok().put("result",res);
    }
    @PostMapping("/searchDriverCurrentOrder")
    @SaCheckLogin
    @Operation(summary = "查询司机当前订单表单")
    public R searchDriverCurrentOrder() {
        long driverId=StpUtil.getLoginIdAsLong();
        SearchDriverCurrentOrderForm form=new SearchDriverCurrentOrderForm();
        form.setDriverId(driverId);
        HashMap res = orderService.searchDriverCurrentOrder(form);
        return R.ok().put("result", res);
    }
    @PostMapping("/searchOrderForMoveById")
    @SaCheckLogin
    @Operation(summary = "查询订单信息用于司乘同显")
    public R searchOrderForMoveById(@RequestBody @Valid SearchOrderForMoveByIdForm form){
        long driverId=StpUtil.getLoginIdAsLong();
        form.setDriverId(driverId);
        HashMap res=orderService.searchOrderForMoveById(form);
        return R.ok().put("result",res);
    }
    @PostMapping("/arriveStartPlace")
    @SaCheckLogin
    @Operation(summary = "查询订单信息用于司乘同显")
    public R arriveStartPlace(@RequestBody @Valid ArriveStartPlaceForm form){
        long driverId=StpUtil.getLoginIdAsLong();
        form.setDriverId(driverId);
        int rows=orderService.arriveStartPlace(form);
        return R.ok().put("rows",rows);
    }
    @PostMapping("/startDriving")
    @SaCheckLogin
    @Operation(summary = "开始代驾")
    public R startDriving(@RequestBody @Valid StartDrivingForm form){
        long driverId=StpUtil.getLoginIdAsLong();
        form.setDriverId(driverId);
        int rows=orderService.startDriving(form);
        return R.ok().put("rows",rows);
    }
    @PostMapping("/updateOrderStatus")
    @SaCheckLogin
    @Operation(summary = "更新订单状态")
    public R updateOrderStatus(@RequestBody @Valid UpdateOrderStatusForm form){
        int rows=orderService.updateOrderStatus(form);
        return R.ok().put("rows",rows);
    }
    @PostMapping("/updateBillFee")
    @SaCheckLogin
    @Operation(summary = "更新订单状态")
    public R updateBillFee(@RequestBody @Valid UpdateBillFeeForm form){
        long driverId=StpUtil.getLoginIdAsLong();
        form.setDriverId(driverId);
        int rows=orderService.updateOrderBill(form);
        return R.ok().put("rows",rows);
    }

    @PostMapping("/searchReviewDriverOrderBill")
    @SaCheckLogin
    @Operation(summary = "更新订单状态")
    public R searchReviewDriverOrderBill(@RequestBody @Valid SearchReviewDriverOrderBillForm form){
        long driverId=StpUtil.getLoginIdAsLong();
        form.setDriverId(driverId);
        HashMap map=orderService.searchReviewDriverOrderBill(form);
        return R.ok().put("result",map);
    }
    @PostMapping("/searchOrderStatus")
    @SaCheckLogin
    @Operation(summary = "查询订单状态")
    public R searchOrderStatus(@RequestBody @Valid SearchOrderStatusForm form){
        long driverId=StpUtil.getLoginIdAsLong();
        form.setDriverId(driverId);
        Integer status=orderService.searchOrderStatus(form);
        return R.ok().put("result",status);
    }
    @PostMapping("/updateOrderAboutPayment")
    @SaCheckLogin
    @Operation(summary = "更新订单相关付款信息")
    public R updateOrderAboutPayment(@RequestBody @Valid UpdateOrderAboutPaymentForm form){
        long driverId=StpUtil.getLoginIdAsLong();
        String res=orderService.updateOrderAboutPayment(driverId,form);
        return R.ok().put("result",res);
    }
    @PostMapping("/searchDriverOrderByPage")
    @SaCheckLogin
    @Operation(summary = "更新订单相关付款信息")
    public R searchDriverOrderByPage(@RequestBody @Valid SearchDriverOrderByPageForm form){
        long driverId=StpUtil.getLoginIdAsLong();
        form.setDriverId(driverId);
        PageUtils res=orderService.searchDriverOrderByPage(form);
        return R.ok().put("result",res);
    }
    @PostMapping("/searchOrderById")
    @SaCheckLogin
    @Operation(summary = "更新订单相关付款信息")
    public R searchOrderById(@RequestBody @Valid SearchOrderByIdForm form){
        long driverId=StpUtil.getLoginIdAsLong();
        form.setDriverId(driverId);
        HashMap res=orderService.searchOrderById(form);
        return R.ok().put("result",res);
    }
}
